﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ExpenseReportControl.ascx.cs" Inherits="WebSiteAlex.ExpenseReportControl" %>

<%@ Register src="ControlExpenseReport.ascx" tagname="ControlExpenseReport" tagprefix="uc1" %>

<asp:Panel ID="listPanel" runat="server">
    <h1>Expense Reports</h1>
    
    <asp:LinqDataSource ID="source" runat="server" OnSelecting="OnLinqDataSourceSelecting">
    </asp:LinqDataSource>

    <table>
        <tr>
            <td><b>Name:</b></td>
            <td>
                <asp:TextBox required="false" ID="editSearchName" runat="server" />
            </td>
            <td>Status</td>
            <td>
                <asp:DropDownList ID="editSearchState" runat="server" DataTextField="Name" DataValueField="Name" />
            </td>
        </tr>
        <tr>
            <td colspan="2"> 
                <asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="OnSearch" />
                <asp:Button ID="btnNew" runat="server" OnClick="OnNew" Text="New" />
            </td>
        </tr>
    </table>
    <br />
    <asp:GridView ID="grid" runat="server" AutoGenerateColumns="False" EmptyDataText="No expense reports to list." 
        DataKeyNames="Id" OnSelectedIndexChanged="OnSelected" AllowPaging="True" AllowSorting="True" 
        DataSourceID="source">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:ImageButton ID="btnSelect" runat="server" CommandName="Select" 
                    ImageUrl="~/Images/Edit.gif" Visible='<%# Eval("State").Equals("Waiting") %>' />
                </ItemTemplate>
            </asp:TemplateField>

            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />  
            <asp:BoundField DataField="CreationDate" HeaderText="CreationDate" SortExpression="CreationDate" />
            <asp:BoundField DataField="State" HeaderText="Status" SortExpression="State" />  
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" 
                        ImageUrl="~/Images/Delete.jpg" CommandArgument='<%# Eval("Id") %>' 
                        OnClick="OnDelete" OnClientClick='confirm("Are you sure?")'
                        Visible='<%# Eval("State").Equals("Waiting") %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Button ID="btnSubmit" runat="server" CommandArgument='<%# Eval("Id") %>' 
                        OnClick="OnSubmit" OnClientClick='confirm("Are you sure?")'
                        Visible='<%# Eval("State").Equals("Waiting") %>' Text="Submit" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
</asp:Panel>

<asp:Panel ID="editPanel" runat="server" Visible="false">
    <h2>Edit Expense Report</h2>
    <br />
    <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="OnSave" />
    <asp:Button ID="btnReturn" runat="server" Text="Back" OnClick="OnReturn" CausesValidation="false" />
    
    <br />
    
    <uc1:ControlExpenseReport ID="controlExpenseReport" runat="server" />
    
</asp:Panel>
